<template>
    <div class="mobile-bind">
        <div>
            <div class="cPBoxItm-title">
                <div>验证密码</div>
                <span class="c-recovery" @click="shut"></span>
            </div>
            <div class="setPublic-tipBox">
                <span class="setPublic-tipCont">请输入当前密码</span>
                <span class="setPublic-tipWarning" v-if="tip">
                    <span class="setPublic-tipIcon">&#xe64a;</span>
                    <span class="setPublic-tipErr">{{content}}</span>
                </span>
            </div>
            <div class="setPublic-input">
                <input type="password" class="setPublic-inputCont" v-model="pas">
            </div>
            <thereImg v-on:thereCode="thereCode" v-if="thereOpen" :cp="chp"></thereImg>
            <div class="setPublic-next">
                <div class="setPublic-nextOne nice-btn-lBlue" @click="next">下一步</div>
                <div class="setPublic-nextClear" @click="shut">取消</div>
            </div>
        </div>
    </div>
</template>
<script>
    import thereImg from './thereImg.vue'
    export default {
        data(){
          return{
              content:'密码不能为空',
              pas:'',
              tip:0,
              time:0,
              thereN:2,
              chp:true,
              thereOpen:0
          }
        },
        methods:{
            next:function () {
                if(this.pas!=''){
                    if(this.time>=3){
                        this.thereOpen=1;
                        setTimeout(()=>{
                            this.thereOpen=0;
                        },300000)
                    }
                    if(this.thereOpen==0){
                        $.ajax({
                            type:'get',
                            url : '/employee_valid',
                            data:{
                                pwd:this.pas
                            },
                            dataType : 'jsonp',
                            success:(data)=>{
                                if(data.success.opResult==0){
                                    this.$emit('swit');
                                }else if(data.success.opResult==1){
                                    this.content='密码错误！';
                                    this.chp=!this.chp;
                                    this.tip=1;
                                    setTimeout(()=>{ this.tip=0},1500);
                                    if(this.time<3){
                                        this.time++;
                                    }
                                }
                            },
                        });
                    }else {
                        if(this.thereN==0){
                            this.content='验证码错误';
                            this.tip=1;
                            this.chp=!this.chp;
                            setTimeout(()=>{ this.tip=0},1500)
                        }else if(this.thereN==1){
                            $.ajax({
                                type:'get',
                                url : '/employee_valid',
                                data:{
                                    pwd:this.pas
                                },
                                dataType : 'jsonp',
                                success:(data)=>{
                                    if(data.success.opResult==0){
                                        this.$emit('swit')
                                    }else if(data.success.opResult==1){
                                        this.content='密码错误！';
                                        this.tip=1;
                                        setTimeout(()=>{ this.tip=0},1500)
                                    }
                                },
                            });
                        }else if(this.thereN==2){
                            this.content='验证码不能为空';
                            this.tip=1;
                            setTimeout(()=>{ this.tip=0},1500)
                        }
                    }

                }else {
                    this.content='密码不能为空';
                    this.tip=1;
                    setTimeout(()=>{ this.tip=0},1500)
                }
            },
            shut:function () {
                this.$emit('thisKg')
            },
            thereCode:function (val) {
                this.thereN=val;
            }
        },
        components:{
            thereImg:thereImg
        }
    }
</script>